#*****************************************************************************
# Copyright Jack Lee. All rights reserved.
# Licensed under the MIT License.
# Email: 291148484@163.com
# https://blog.csdn.net/qq_28550263?spm=1001.2101.3001.5343
#*****************************************************************************

function Read-Ini {
    param (
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
        [string]$Path
    )

    $iniObj = @{}
    $currentSection = ""

   $IniArray = Get-Content -Path $Path

    foreach ($line in $IniArray) {
        $line = $line.Trim()
        if ($line -match "^\[.*\]$") {
            $currentSection = $line -replace "\[|\]"
            # 以 currentSection 为名，新建一个子哈希表
            $iniObj[$currentSection] = @{}
        }
        elseif ($line -match "(.*)=(.*)") {
            $key,$value = $line -split "="
            $iniObj[$currentSection][$key] = $value
        }
    }
    return $iniObj
}